<template lang="pug">
  div.table-empty
    s-table(
      ref="table"
      :reqUrl="reqUrl"
      reqMethod="GET"
      :column="tableObj.column"
      :filterProps="{ fields: tableObj.searchField }"
    )
      .table-operator(slot="table-operator")
        el-button.gradientVertical(size="large" round @click="actionHandle({}, 'add')") 添加
      template(slot="action" slot-scope="text, scope")
        el-link( @click="actionHandle(scope, 'edit')" type="primary") 编辑
        el-popconfirm(
            title="您确认要删除该项?"
            @confirm="() => actionHandle(scope, 'delete')"
            @onConfirm="() => actionHandle(scope, 'delete')"
          )
            el-link(slot="reference" type="danger") 删除
      template(slot="enabled" slot-scope="text, scope")
        span {{text ? '开启' : '关闭'}}
    add-drawer(:visible.sync="addObj.visible" :type="addObj.type" :id="addObj.id" @getList="() => refreshTable(true)")
</template>
<script>
import { seachConfig, column } from './config'
import AddDrawer from './components/addDrawer'
import { delProductSolution } from '../api.js'
export default {
  name: 'FinanceChargeProjectSet',
  components: {
    AddDrawer
  },
  data () {
    return {
      tableObj: {
        column,
        searchField: seachConfig
      },
      addObj: {
        visible: false,
        type: 'add'
      }
    }
  },
  computed: {
    reqUrl () {
      return 'crm/fin/product_solution/list'
    }
  },
  methods: {
    refreshTable (flag = false) {
      this.$refs.table.refresh(flag)
    },
    actionHandle (row, type) {
      if (type === 'delete') {
        // 删除
        this.delItem(row.id)
        return
      }
      this.addObj = {
        type,
        id: row.id,
        visible: true
      }
    },

    delItem (id) {
      delProductSolution({ id }).then(res => {
        console.log(res)
        this.refreshTable()
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.table-operator{
  margin-bottom: 18px
}
::v-deep{
  .tableWrapper{
    padding: 0
  }
}
</style>
